#include <dlfcn.h>
#include <string.h>

#include <iostream>

#include "dynclass.h"

int main(int argc, char **argv)
{
    auto handle = dlopen("./libtest1.so", RTLD_LAZY);
    if (!handle) {
        std::cout << "open failed!" << std::endl;
        return -1;
    }
    std::cout << "open succese!" << std::endl;
    do {
        Plugin *plugin = (Plugin *)dlsym(handle, "exports");
        if (!plugin) {
            std::cout << "plugin failed!" << dlerror() << std::endl;
            break;
        }

        std::cout << sizeof(Test) << "name: :" << plugin->mPluginName << " version :" << plugin->mPluginVersion << std::endl;
        if (!plugin->mIsPluginClass("Test", sizeof(Test))) {
            std::cout << "Test failed!" << std::endl;
            break;
        }
        Test *processor = (Test *)plugin->mCreateFunc();
        if (!processor) {
            std::cout << "process null" << std::endl;
            break;
        }

        std::cout << "version:" << processor->version() << "4+5=" << processor->function_add(4, 5) << std::endl;
        // std::cout << "version:" << processor->versions() << std::endl;
    } while (0);

    dlclose(handle);
    return 0;
}